home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / Tool Chest / Testing & Debugging / Mac OS Development Toolkit / Automation Essentials 2.3.0 / Host Automation Folder / VU External Tool libs / MemoryMonitor.vulib < prev    next >
Encoding:
Text File  |  1998-03-19  |  14.0 KB  |  423 lines  |  [TEXT/MPS ]

  1. #
  2. #    File:        MemoryMonitor.vulib
  3. #    
  4. #    Written by:    Test Tools Engineering Support
  5. #
  6. #    Contents:    Task and service definitions for MemoryMonitor
  7. #
  8. #    Copyright © 1992-1997 Apple Computer, Inc.  All rights reserved.
  9. #
  10. #    Change history: (most recent first)
  11. #    Version      Date        Who        Comments
  12. #    =======    ========    ===        ===================
  13. #    1.0.6    02/04/97    JAS        Added 'vers' resources to library.
  14. #                                These should always match tool version when tool is revved.
  15. #            02/04/97    JAS        Updated for VU 2.1
  16. #
  17. #
  18. #
  19. #######################################################################################
  20. #    InitMemoryMonitor( OnTarget := false )
  21. #
  22. #    Prepares Memory Monitor as an external tool.
  23. #
  24. # Input:
  25. #
  26. #    OnTarget
  27. #        Pass in true if Memory Monitor is to run on a target, false for the Host.
  28. #        By default Memory Monitor runs on the Host
  29. #    
  30. #######################################################################################
  31. Task InitMemoryMonitor( OnTarget := false )
  32. Begin
  33.     x := MemoryMonitor( "Initialize", OnTarget );
  34.     Script_Error := ScriptError();
  35.     return { x[1], x[2], x[3], Script_Error };
  36. end;
  37.  
  38.  
  39. #######################################################################################
  40. #    QuitMemoryMonitor()
  41. #
  42. #    Causes Memory Monitor application to 'Quit'.
  43. #
  44. #######################################################################################
  45. Task QuitMemoryMonitor()
  46. Begin
  47.     x := MemoryMonitor( "Quit" );
  48.     Script_Error := ScriptError();
  49.     return { x[1], x[2], x[3], Script_Error };
  50. end;
  51.  
  52.  
  53. #######################################################################################
  54. #    GetAllProcesses( pCallAsync := false )
  55. #
  56. #    Returns a list of all processes which are currently running.
  57. #
  58. # Input:
  59. #
  60. #    pCallAsync    boolean        Determines wheather the tool is called asynchronously
  61. #
  62. # Output:
  63. #
  64. #    The return value is a list of ProcessRecord elements: { ProcRec, ProcRec, ... }
  65. #    Each ProcessRecord element is a list containing the following elements
  66. #    
  67. # Index    Data Type    Label        Significance
  68. # ----- ---------   -----       ------------
  69. #    1    string        Name        The name of the process        
  70. #    2    string        Type        The 4 letter type code    
  71. #    3    string        Signature    The 4 letter signature code        
  72. #    4    string        Location    Decimal digits of address of the heap zone
  73. #    5    string        Size        Decimal digits of heap zone size in bytes
  74. #    6    string        Free        Decimal digits of Free Memory in bytes
  75. #    7    string        Pathname    Pathname to the file from which the process came
  76. #    
  77. #######################################################################################
  78. Task GetAllProcesses( pCallAsync := false )
  79. Begin
  80.     x := MemoryMonitor( "GetAllProcesses" ) Async:pCallAsync;
  81.     Script_Error := ScriptError();
  82.     return { x[1], x[2], x[3], Script_Error };
  83. end;
  84.  
  85.  
  86. #######################################################################################
  87. #    GetProcessInfo( ProcName, pCallAsync := false )
  88. #
  89. #    Returns Process Manager information for the process specified
  90. #    by the ProcName paramter
  91. #
  92. # Input:
  93. #
  94. #    ProcName    string        The name of the process of interest
  95. #    pCallAsync    boolean        Determines wheather the tool is called asynchronously
  96. #
  97. # Output:
  98. #
  99. #    return value is a ProcessRecord containing the following elements
  100. #    
  101. # Index    Data Type    Label        Significance
  102. # ----- ---------   -----       ------------
  103. #    1    string        Name        The name of the process        
  104. #    2    string        Type        The 4 letter type code    
  105. #    3    string        Signature    The 4 letter signature code        
  106. #    4    string        Location    Decimal digits of address of the heap zone
  107. #    5    string        Size        Decimal digits of heap zone size in bytes
  108. #    6    string        Free        Decimal digits of Free Memory in bytes
  109. #    7    string        Pathname    Pathname to the file from which the process came
  110. #    
  111. #######################################################################################
  112. Task GetProcessInfo( ProcName, pCallAsync := false )
  113. Begin
  114.     x := MemoryMonitor( "GetProcessInfo", ProcName ) Async:pCallAsync;
  115.     Script_Error := ScriptError();
  116.     return { x[1], x[2], x[3], Script_Error };
  117. end;
  118.  
  119.  
  120. #######################################################################################
  121. #    GetZoneMap(  ZoneSelector, pCallAsync := false )
  122. #
  123. #    Returns a list containing location and size info for the specified zone 
  124. #    and all zones nested within the specified zone.
  125. #
  126. # Input:
  127. #
  128. #    ZoneSelector        Determines which heap zone, may be of two forms:
  129. #
  130. #    Form 1:    string        
  131. #        The process/zone name        
  132. #            
  133. #        Example 'Finder'    - the Finder's heap zone
  134. #            
  135. #    Form 2: { string [[,integer] ...] }    
  136. #        Element 1 determines the root heap zone 
  137. #        Each following index specifies which nested heap zone
  138. #
  139. #        Example { 'Virtual User', 1 } - first nested heap zone within Virtual User
  140. #
  141. #        There are two names which can be used in the place of a prcess name
  142. #        'SystemZone' and 'MultiFinderZone'. These values allow access  
  143. #        to the two root heap zones.
  144. #
  145. #        Example { 'System', 1 } - The first nested heap within the System heap.
  146. #
  147. #    pCallAsync    boolean        Determines wheather the tool is called asynchronously
  148. #
  149. # Output:
  150. #
  151. #    The return value is a list of ZoneRecord elements: { ZoneLoc, ZoneLoc, ... }
  152. #    Note the fourth element is a list which may contain more ZoneRecord elements.
  153. #    Since heap zones can be nested, ZoneRecords can also be nested.
  154. #    
  155. # Index    Data Type    Label            Significance
  156. # ----- ---------   -----           ------------
  157. #    1    string        StartAddress    Decimal digits of address where heap zone begins
  158. #    2    string        EndAddress        Decimal digits of address where heap zone ends
  159. #    3    string        Size            Decimal digits of size of the heap zone in bytes
  160. #    4    list        NestedZones        List of all nested heap zones
  161. #    
  162. #######################################################################################
  163. Task GetZoneMap(  ZoneSelector := "", pCallAsync := false )
  164. Begin
  165.     x := MemoryMonitor( "GetZoneMap", ZoneSelector ) Async:pCallAsync;
  166.     Script_Error := ScriptError();
  167.     return { x[1], x[2], x[3], Script_Error };
  168. end;
  169.  
  170.  
  171. #######################################################################################
  172. #    GetZoneTotals( ZoneSelector, pCallAsync := false )
  173. #
  174. #    Returns a summary of how memory is allocated within a specified heap zone.
  175. #    The total bytes and number of blocks is returned for each of the following
  176. #    catagories : 
  177. #        Free,  
  178. #        Non-Relocatable,  
  179. #        Relocatable,   
  180. #        Relocatable/Locked, 
  181. #        Relocatable/Not Locked & Purgable
  182. #    
  183. #    This is similar to Macsbug's HT (heap totals) command
  184. #
  185. # Input:
  186. #
  187. #    ZoneSelector        Determines which heap zone, may be of two forms:
  188. #
  189. #    Form 1:    string        
  190. #        The process/zone name        
  191. #            
  192. #        Example 'Finder'    - the Finder's heap zone
  193. #            
  194. #    Form 2: { string [[,integer] ...] }    
  195. #        Element 1 determines the root heap zone 
  196. #        Each following index specifies which nested heap zone
  197. #
  198. #        Example { 'Virtual User', 1 } - first nested heap zone within Virtual User
  199. #
  200. #        There are two names which can be used in the place of a prcess name
  201. #        'SystemZone' and 'MultiFinderZone'. These values allow access  
  202. #        to the two root heap zones.
  203. #
  204. #        Example { 'System', 1 } - The first nested heap within the System heap.
  205. #
  206. #    pCallAsync    boolean        Determines wheather the tool is called asynchronously
  207. #
  208. # Output:
  209. #
  210. #    return value is a list of one element for each catagory of block allocation type
  211. #    Each element is itself a list containing two values, number of blocks and total bytes 
  212. #    'number of blocks' is an integer value, and 'total bytes' is a string of decimal digits
  213. #    
  214. # Index    Data Type    Label        Significance
  215. # ----- ---------   -----       ------------
  216. #    1    list        Free                                    { number of blocks, total bytes }
  217. #    2    list        Non-Relocatable                            { number of blocks, total bytes }
  218. #    3    list        Relocatable                                { number of blocks, total bytes }
  219. #    4    list        Relocatable/Locked                        { number of blocks, total bytes }
  220. #    5    list        Relocatable/Not Locked & Purgable        { number of blocks, total bytes }
  221. #    6    list        Total                                    { number of blocks, total bytes }
  222. #    
  223. #######################################################################################
  224. Task GetZoneTotals( ZoneSelector, pCallAsync := false )
  225. Begin
  226.     x := MemoryMonitor( "GetZoneTotals", ZoneSelector ) Async:pCallAsync;
  227.     Script_Error := ScriptError();
  228.     return { x[1], x[2], x[3], Script_Error };
  229. end;
  230.  
  231.  
  232. #######################################################################################
  233. #    CheckZone( ZoneSelector, pCallAsync := false )
  234. #
  235. #    Checks the Memory Manager data structures within the specified heap zone
  236. #    Returns true if no inconsistencies are found.
  237. #    
  238. #    This is similar to Macsbug's HC (heap check) command
  239. #
  240. # Input:
  241. #
  242. #    ZoneSelector        Determines which heap zone, may be of two forms:
  243. #
  244. #    Form 1:    string        
  245. #        The process/zone name        
  246. #            
  247. #        Example 'Finder'    - the Finder's heap zone
  248. #            
  249. #    Form 2: { string [[,integer] ...] }    
  250. #        Element 1 determines the root heap zone 
  251. #        Each following index specifies which nested heap zone
  252. #
  253. #        Example { 'Virtual User', 1 } - first nested heap zone within Virtual User
  254. #
  255. #        There are two names which can be used in the place of a prcess name
  256. #        'SystemZone' and 'MultiFinderZone'. These values allow access  
  257. #        to the two root heap zones.
  258. #
  259. #        Example { 'System', 1 } - The first nested heap within the System heap.
  260. #
  261. #    pCallAsync    boolean        Determines wheather the tool is called asynchronously
  262. #
  263. # Output:
  264. #
  265. #    The return value is a symbol : either true or false
  266. #    
  267. #######################################################################################
  268. Task CheckZone( ZoneSelector, pCallAsync := false )
  269. Begin
  270.     x := MemoryMonitor( "CheckZone", ZoneSelector ) Async:pCallAsync;
  271.     Script_Error := ScriptError();
  272.     return { x[1], x[2], x[3], Script_Error };
  273. end;
  274.  
  275.  
  276.  
  277. #######################################################################################
  278. #    GetAboutThisMacintosh( pCallAsync := false )
  279. #
  280. #    2
  281. #    
  282. # Input:
  283. #
  284. #    pCallAsync        boolean        Determines wheather the tool is called asynchronously
  285. #
  286. # Output:
  287. #
  288. #    The return value is a list of items from Finder's About Box ( "About This Macintosh" ).
  289. #    Each element of the list is as follows:
  290. #
  291. # Index    Data Type    Label            Significance
  292. # ----- ---------   -----              ------------
  293. #    1    string        PhysicalRAM        Decimal digits of 'Built-in Memory'
  294. #    2    string        LogicalRAM        Decimal digits of 'Total Memory'
  295. #    3    string        LargestBlock    Decimal digits of 'Largest unused block'
  296. #    4    list        Processes        List of info for each process
  297. #    
  298. #    The 'Processes' element is a list containing one of the following records 
  299. #    for each process.
  300. #
  301. # Index    Data Type    Label            Significance
  302. # ----- ---------   -----              ------------
  303. #    1    string        Name            Process name
  304. #    2    string        LargestBlock    Decimal digits of process size in bytes
  305. #
  306. #######################################################################################
  307. Task GetAboutThisMacintosh( pCallAsync := false )
  308. Begin
  309.     x := MemoryMonitor( "GetAboutThisMacintosh" ) Async:pCallAsync;
  310.     Script_Error := ScriptError();
  311.     return { x[1], x[2], x[3], Script_Error };
  312. end;
  313.  
  314. #######################################################################################
  315. #    ReadBytes( pAddress, pCount, pCallAsync := false )
  316. #
  317. #    Returns a list of contiguous bytes from memory
  318. #    
  319. # Input:
  320. #
  321. #    pAddress        list        The location of the first byte to read.
  322. #                                The list must contain the High & Low words of the address
  323. #
  324. #    pCount            integer        The number of bytes to read
  325. #
  326. #    pCallAsync        boolean        Determines wheather the tool is called asynchronously
  327. #
  328. # Output:
  329. #
  330. #    The return value is a list of integers.
  331. #    Each one is equal to the value of the byte read from memory.
  332. #
  333. #######################################################################################
  334. Task ReadBytes( pAddress, pCount, pCallAsync := false )
  335. Begin
  336.     x := MemoryMonitor( "ReadBytes", pAddress, pCount ) Async:pCallAsync;
  337.     Script_Error := ScriptError();
  338.     return { x[1], x[2], x[3], Script_Error };
  339. end;
  340.  
  341. #######################################################################################
  342. #    MacsbugCmd( Commands, Label := "Memory Moniotr", RemainInMacsBug := false, pCallAsync := false )
  343. #
  344. #    Executes a Macsbug command, via Macsbug command line
  345. #    
  346. # Input:
  347. #
  348. #    Commands        string        One or more Macsbug commands, separated by semi-colons.
  349. #
  350. #    Label            string        Optional label which is desplayed in Macsbug,
  351. #                                prior to command line execution
  352. #
  353. #    RemainInMacsBug    string        if false, a "Go" command is appended to the command line
  354. #                                otherwise, no "Go" command is appeded. This makes it possible
  355. #                                to remain in Macsbug ( for what ever reason )
  356. #
  357. #    pCallAsync        boolean        Determines wheather the tool is called asynchronously
  358. #
  359. # Output:
  360. #
  361. #    The return value is the 'true' symbol if successful, otherwise 'undefined'
  362. #
  363. #######################################################################################
  364. Task MacsbugCmd( CommandLine, Label := "Memory Monitor", RemainInMacsBug := false, pCallAsync := false )
  365. Begin
  366.         ###    Append a "Go" command so we won't stay in Macsbug
  367.     if RemainInMacsBug
  368.     begin
  369.         CommandLine := "{Label}; {CommandLine}";
  370.     end;
  371.     else
  372.     begin
  373.         CommandLine := "{Label}; {CommandLine} ;g";
  374.     end;
  375.     
  376.     x := MemoryMonitor( "MacsbugCmd", CommandLine ) Async:pCallAsync;
  377.     Script_Error := ScriptError();
  378.     return { x[1], x[2], x[3], Script_Error };
  379. end;
  380.  
  381.  
  382. #######################################################################################
  383. #    MemoryMonitor Tool Declaration
  384. #
  385. #    Defines the V.U. scripting interface to Memory Monitor
  386. #
  387. Tool MemoryMonitor s:'MMTL'
  388. begin
  389.         #####################################################
  390.         ### Services specific to Memory Monitor:
  391.     
  392.         ### Process Manager
  393.     Service "GetAllProcesses"( )                 return 'list';
  394.     Service "GetProcessInfo"( 'string' )         return 'list';
  395.  
  396.         ### Heap Zone
  397.     Service "GetZoneMap"( 'undefined' )            return 'list';
  398.     Service "GetZoneTotals"( 'undefined' )        return 'list';
  399.     Service "CheckZone"( 'undefined' )            return 'symbol';
  400.  
  401.         ### Finder's About Box
  402.     Service "GetAboutThisMacintosh"( )            return 'list';
  403.  
  404.         ### Reading Memory
  405.     Service "ReadBytes"( 'list', 'integer' )    return 'list';
  406.  
  407.         ### Macsbug Command
  408.     Service "MacsbugCmd"( 'string' )            return 'symbol';
  409.     
  410.         #####################################################
  411.         ### Services common to all Virtual User external tools:
  412.     
  413.     Service "Initialize"        ( 'undefined' );
  414.     Service "Cancel"            ( 'string' );
  415.     Service "Poll"                ( 'string' )     return 'string';
  416.     Service "ServiceSupported"    ( 'string' )     return 'undefined';
  417.     Service "GetToolServices"    ()                 return 'list';
  418.     Service "GetToolVersion"    ()                 return 'list';
  419.     Service "Quit"();
  420.  
  421. end;
  422.  
  423.